package com.jianguo.web.controller.user;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianguo.common.annotation.Log;
import com.jianguo.common.core.controller.BaseController;
import com.jianguo.common.core.domain.AjaxResult;
import com.jianguo.common.enums.BusinessType;
import com.jianguo.user.domain.PzRelation;
import com.jianguo.user.service.IPzRelationService;
import com.jianguo.common.utils.poi.ExcelUtil;
import com.jianguo.common.core.page.TableDataInfo;

/**
 * 关系Controller
 *
 * @author xjj
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/user/userRelation")
public class PzRelationController extends BaseController
{
    @Autowired
    private IPzRelationService pzRelationService;

    /**
     * 查询关系列表
     */
    @PreAuthorize("@ss.hasPermi('user:userRelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(PzRelation pzRelation)
    {
        startPage();
        List<PzRelation> list = pzRelationService.selectPzRelationList(pzRelation);
        return getDataTable(list);
    }

    /**
     * 导出关系列表
     */
    @PreAuthorize("@ss.hasPermi('user:userRelation:export')")
    @Log(title = "关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PzRelation pzRelation)
    {
        List<PzRelation> list = pzRelationService.selectPzRelationList(pzRelation);
        ExcelUtil<PzRelation> util = new ExcelUtil<PzRelation>(PzRelation.class);
        util.exportExcel(response, list, "关系数据");
    }

    /**
     * 获取关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:userRelation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pzRelationService.getById(id));
    }

    /**
     * 新增关系
     */
    @PreAuthorize("@ss.hasPermi('user:userRelation:add')")
    @Log(title = "关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PzRelation pzRelation) {
        return toAjax(pzRelationService.save(pzRelation));
    }

    /**
     * 修改关系
     */
    @PreAuthorize("@ss.hasPermi('user:userRelation:edit')")
    @Log(title = "关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PzRelation pzRelation) {
        return toAjax(pzRelationService.updateById(pzRelation));
    }

    /**
     * 删除关系
     */
    @PreAuthorize("@ss.hasPermi('user:userRelation:remove')")
    @Log(title = "关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pzRelationService.removeByIds(Arrays.asList(ids)));
    }
}
